package com.maxatime.web.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.maxatime.common.constant.BusinessContents;
import com.maxatime.pojo.dto.ExamStorageDTO;
import com.maxatime.pojo.entity.ExamStorage;
import com.maxatime.service.Ssbkaoshi5;

//vue3月份考试
@Controller
@RequestMapping("/Ssbkaoshi5")
public class Ssbcontroller5 {
		
		@Autowired
		Ssbkaoshi5 ssbkaoshi5;
	
		// 查询
		@RequestMapping("/quest")
		@ResponseBody
		public Map<String, Object> quest(@RequestBody ExamStorageDTO examStorageDTO) {
//			JSONObject jsonObj = JSONObject.parseObject(jsonStr);
//			String typeId = jsonObj.getString("typeId");//获取typeId，查第二个表里的名称
//			String goodsName = jsonObj.getString("goodsName");
//			int pageNum = jsonObj.getIntValue("pageNum");
//			int pageSize = jsonObj.getIntValue("pageSize");
			Map<String, Object> m = new HashMap<>();
//			ExamStorage examStorage  = new ExamStorage();
//			examStorage.setTypeId(typeId);//获取typeId，查第二个表里的名称
//			examStorage.setGoodsName(goodsName);
//			examStorage.setPageNum(pageNum);
//			examStorage.setPageSize(pageSize);
			Map<String, Object> list = ssbkaoshi5.list(examStorageDTO);
			m.put(BusinessContents.CODE, "0000");
			m.put(BusinessContents.MSG, "交易成功");
			m.put(BusinessContents.DATA, list.get("list"));
			m.put("pageInfo", list.get("pageInfo"));
			System.out.println("查询:"+list);
			return m;
		}
		// 新增
		@RequestMapping("/save")
		@ResponseBody
		public Map<String, Object> save(@RequestBody ExamStorage examStorage) {
			Map<String, Object> m=  new HashMap<>();
			System.out.println("123:::"+examStorage);
			ssbkaoshi5.insertSelective(examStorage);
			m.put(BusinessContents.CODE, "1111");
			m.put(BusinessContents.MSG, "新增成功");
			return m;
		}
		
		// 删除
		@RequestMapping("/delete")
		@ResponseBody
		public Map<String, Object> delete(@RequestBody String jsonStr) {
			JSONObject jsonObj = JSONObject.parseObject(jsonStr);
			int pkId = jsonObj.getInteger("pkId");
			Map<String, Object> m = new HashMap<>();
			ssbkaoshi5.deleteByPrimaryKey(pkId);
			m.put(BusinessContents.CODE, "2222");
			m.put(BusinessContents.MSG, "删除成功");
			return m;
		}
		
		// 修改反显 
		@RequestMapping("/find")
		@ResponseBody
		public Map<String, Object> find(@RequestBody String jsonStr) {
			JSONObject jsonObj = JSONObject.parseObject(jsonStr);
			int pkId = jsonObj.getInteger("pkId");
			Map<String, Object> m = new HashMap<>();
			ExamStorage examStorage = ssbkaoshi5.find(pkId);
			m.put(BusinessContents.CODE, "3333");
			m.put(BusinessContents.MSG, "反显成功");
			m.put(BusinessContents.DATA, examStorage);
			return m;
		}
		
		// 修改
		@RequestMapping("/update")
		@ResponseBody
		public Map<String, Object> update(@RequestBody ExamStorage examStorage) {
			Map<String, Object> m = new HashMap<>();
			ssbkaoshi5.updateByPrimaryKeySelective(examStorage);
			m.put(BusinessContents.CODE, "4444");
			m.put(BusinessContents.MSG, "修改成功");
			return m;
		}
		
}
